home *** CD-ROM | disk | FTP | other *** search
- Path: in1.uu.net!van-bc!usenet
- From: ralphb@wimsey.com
- Newsgroups: comp.lang.c
- Subject: Assistance needed - pointers to functions
- Date: 18 Feb 1996 01:10:30 GMT
- Organization: Online at Wimsey
- Message-ID: <4g5ua6$f2i@wolfe.wimsey.com>
- Reply-To: ralphb@wimsey.com
- NNTP-Posting-Host: pm024.vcr.wis.net
- X-Newsreader: IBM NewsReader/2 v1.9d - NLS
-
- Hi, Folks! I have a stumbling block regarding pointers to functions,
- in that I cannot seem to fathom how to get hold of variables in other
- functions. For example, in the code segment below I would eventually
- like to be able to search student records which have been defined,
- and filled in the code seg following this one:
-
- #include <stdio.h>
- #include <string.h>
- #include "ass2.h"
-
- int dosection(int selection)
- {
- switch(selection)
- {
- case SEARCH:
- /* do search routines here */
- printf("\nSEARCH");
- return 1;
- :
- : (Stuff deleted)
- :
- default:
- return 0;
- }
- }
-
- Below is the function that fills up a few student records initially.
-
- int search_student_record()
- {
- FILE *fp;
- STUDENT_RECORD S; /* Define S as a student record */
- int i=0; /* Index into student record element */
- INDEX student_index[MAX_STUDENT_REC]; /*Define student_index array of type INDEX */
- long f_pos=0;
- fp = fopen("student.dat","r");
- fseek(fp,0,SEEK_SET);
- if (fp == NULL)
- return 1;
- else
- {
- while (!feof(fp))
- {
- f_pos = ftell(fp);
- fread(&S,sizeof(S),1,fp);
-
- student_index[i].f_pos = f_pos;
- student_index[i].id = S.id;
- strcpy(student_index[i].name,S.name);
- i++;
- }
- return 0;
- }
- }
-
- So I have a array of student_index whose structure is in a header file
- somewhere else. The code compiles perfectly (no errors, no warnings).
-
- Now the question:
-
- How do I reference student_index[i] in the first function so that I
- can search through it and make modifications, keeping in mind that
- these functions are seperate .c files?
-
- I have many such functions where I would need to get to a structure,
- or even a simple int variable all by itself, and use it inside of a
- different function, so any help you can provide on this is much
- appreciated.
-
- Thanks,
- Ralph
-
-